<template >
  <div style="min-width:1636px;"  >
    <div class="front-notice" style=" background-color: #ccdcd9 "><i class="el-icon-bell" style="margin-right: 2px;"></i>公告：{{ top }}</div>
    <!--头部-->
    <div class="front-header">
      <div class="front-header-left">
        <img src="@/assets/imgs/qiantai.png" alt="">
        <div class="title">黑洞论坛</div>
      </div>
      <div class="front-header-center">
        <div style="background-color: #f0f0f0">
          <el-menu :default-active="$route.path" mode="horizontal" router>
						<el-menu-item  index="/front/home">首页</el-menu-item>
						<el-menu-item  index="/front/activity">活动中心</el-menu-item>
						<el-menu-item  index="/front/multiplayer">交流大厅</el-menu-item>
						<el-menu-item  index="/front/exchange">私聊</el-menu-item>
            <el-menu-item  index="/front/userAi">AI工具</el-menu-item>
						<el-menu-item  index="/front/person">个人中心</el-menu-item>
            <el-menu-item  index="/front/other">服务</el-menu-item>
            
          </el-menu>
        </div>
      </div>
      <div >
        <el-input style="width: 260px; margin-right: 10px" placeholder="请输入相关关键字" clearable v-model="title"></el-input>
        <el-button type="info" @click="goSearch" >搜索</el-button>
      </div>
      <div class="front-header-right">
        <!--添加游客观览-->
        <div v-if="!user.username">
          <el-button @click="$router.push('/login')">登录</el-button>
          <el-button @click="$router.push('/register')">注册</el-button>
        </div>
        <div v-else>
          <el-dropdown>
            <div class="front-header-dropdown">
              <img :src="user.avatar || 'https://drd-web.oss-cn-beijing.aliyuncs.com/wutoxiang.png'" />
              <div style="margin-left: 10px">
                <span>{{ user.name }}</span><i class="el-icon-arrow-down" style="margin-left: 5px"></i>
              </div>
            </div>
            <el-dropdown-menu slot="dropdown">
              <el-dropdown-item>
                <div style="text-decoration: none" @click="logOut">退出</div>
              </el-dropdown-item>
              <el-dropdown-item v-if="user.role==='ADMIN'" @click.native="$router.push('../home')">去后台</el-dropdown-item>
            </el-dropdown-menu>
          </el-dropdown>
        </div>
      </div>
    </div>
    <!--主体-->
    <div style=" min-height:600px;" class="main-body">
      <router-view  ref="child" @update:user="updateUser" />
    </div>

    <dibuBAH></dibuBAH>
    <div class="kuang" style="min-width:1636px;height: 100%;">
      <div class="bubble"></div>
      <div class="bubble"></div>
      <div class="bubble"></div>
      <div class="bubble"></div>
      <div class="bubble"></div>
      <div class="bubble"></div>
      <div class="bubble"></div>
      <div class="bubble"></div>
      <div class="bubble"></div>
      <div class="bubble"></div>
    </div>
  </div>

</template>

<script>
import Search from '@/components/Search.vue'
import dibuBAH from "@/components/dibuBAH.vue";
export default {
  name: "FrontLayout",

  data () {
    return {
      top: '',
      notice: [],
      user: JSON.parse(localStorage.getItem("xm-user") || '{}'),
      title: this.$route.query.title,   //搜索关键字
    }
  },
  components: {
    Search,
    dibuBAH
  },
  mounted() {
    this.loadNotice()
  },
  created() {

  },
  methods: {
    goSearch(){
      window.open("/front/search?title="+ this.title);
    },
    loadNotice() {
      this.$request.get('/notice/selectAll').then(res => {
        this.notice = res.data
        let i = 0
        if (this.notice && this.notice.length) {
          this.top = this.notice[0].content
          setInterval(() => {
            this.top = this.notice[i].content
            i++
            if (i === this.notice.length) {
              i = 0 
            }
          }, 8000)
        }
      })
    },
    updateUser() {
      this.user = JSON.parse(localStorage.getItem('xm-user') || '{}')   // 重新获取下用户的最新信息
    },
    // 退出登录
    logOut() {
      this.$request.post('/logOut',this.user).then(res => {
        localStorage.removeItem("xm-user");
        this.$router.push("/newLogin");
      });
    },
  }

}
</script>

<style scoped>
body {
  background-color: #f5f5f5;
}

.main-content {
  width: 85%;
  margin: 5px auto;
}
.front-notice {
  padding: 5px 20px;
  color: #666;
  font-size: 12px
}
.front-header {
  display: flex;
  height: 60px;
  line-height: 60px;
  border-bottom: 1px solid #eee;
  background: white;
}
.front-header-left {
  width: 350px;
  display: flex;
  align-items: center;
  padding-left: 30px;
}
.front-header-left img, .front-header-dropdown img {
  width: 40px;
  height: 40px;
  border-radius: 50%
}
.front-header-left .title {
  flex: 1;
  color: #000000;
  cursor: pointer;
  margin-left: 10px;
  font-size: 20px;
  font-weight: bold;
}
.front-header-center {
  flex: 1;
}
.front-header-right {
  width: 200px;
  padding-right: 20px;
  text-align: right;
}
.front-header-dropdown {
  display: flex;
  align-items: center;
  justify-content: right;
}
.el-dropdown-menu {
  width: 100px !important;
  text-align: center !important;
}

/*页面具体样式自定义*/
.main-content {
  width: 80%;
  margin: 5px auto;
}
/* ElementUI 样式覆盖 */
.el-menu.el-menu--horizontal {
  border: none !important;
  height: 59px;
}
.kuang{
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: -10;
  background-image: linear-gradient(180deg, #f0f0f0, #045744);

}
.bubble{
  position: absolute;
  border-radius: 50%;
  border: 2px solid #fff;
  box-shadow: inset 0 0 8px  #fff;
  animation: flutter 10s infinite;
  opacity: 0;
}
@keyframes flutter {
  0%{
    transform: translateX(0);
    bottom: -100px;
    opacity: 1;
  }
  50%{
    transform: translateX(100px);
    opacity: 0.5;
  }


  100%{
    transform: translateX(0px);
    bottom: 100%;
    opacity: 0;

  }
}
.bubble:nth-child(1){
  left: -10%;
  width: 50px;
  height: 50px;
  animation-duration: 9s;
  animation-delay: 0.1s;
}
.bubble:nth-child(2){
  left: 15%;
  width: 20px;
  height: 20px;
  animation-duration: 6s;
  animation-delay: 1.5s;

}
.bubble:nth-child(3){
  left: 20%;
  width: 60px;
  height: 60px;
  animation-duration: 10s;



}
.bubble:nth-child(4){
  left: 30%;
  width: 30px;
  height: 30px;
  animation-duration: 5.5s;
  animation-delay: 1.5s;

}
.bubble:nth-child(5){
  left: 40%;
  width: 50px;
  height: 50px;
  animation-duration: 12s;



}
.bubble:nth-child(6){
  left: 50%;
  width: 20px;
  height: 20px;
  animation-duration: 6s;
  animation-delay: 1s;

}
.bubble:nth-child(7){
  left: 60%;
  width: 40px;
  height: 40px;
  animation-duration: 8s;
  animation-delay: 1s;

}
.bubble:nth-child(8){
  left: 65%;
  width: 60px;
  height: 60px;
  animation-duration: 15s;

}
.bubble:nth-child(9){
  left: 80%;
  width: 55px;
  height: 55px;
  animation-duration: 9s;
  animation-delay: 0.5s;

}
.bubble:nth-child(10){
  left: 100%;
  width: 40px;
  height: 40px;
  animation-duration: 12s;

}
.bubble:nth-child(11){
  left: -10%;
  width: 50px;
  height: 50px;
  animation-duration: 9s;
  animation-delay: 0.1s;
}
.bubble:nth-child(12){
  left: 15%;
  width: 20px;
  height: 20px;
  animation-duration: 6s;
  animation-delay: 1.5s;

}
.bubble:nth-child(13){
  left: 20%;
  width: 60px;
  height: 60px;
  animation-duration: 10s;



}
.bubble:nth-child(14){
  left: 30%;
  width: 30px;
  height: 30px;
  animation-duration: 5.5s;
  animation-delay: 1.5s;

}
.bubble:nth-child(15){
  left: 40%;
  width: 50px;
  height: 50px;
  animation-duration: 12s;



}
.bubble:nth-child(16){
  left: 50%;
  width: 20px;
  height: 20px;
  animation-duration: 6s;
  animation-delay: 1s;

}
.bubble:nth-child(17){
  left: 60%;
  width: 40px;
  height: 40px;
  animation-duration: 8s;
  animation-delay: 1s;

}
.bubble:nth-child(18){
  left: 65%;
  width: 60px;
  height: 60px;
  animation-duration: 15s;

}
.bubble:nth-child(19){
  left: 80%;
  width: 55px;
  height: 55px;
  animation-duration: 9s;
  animation-delay: 0.5s;

}
.bubble:nth-child(20){
  left: 100%;
  width: 40px;
  height: 40px;
  animation-duration: 12s;

}
</style>